#!/usr/bin/perl 
use DBI;
use CGI;
use TTraker;
use strict;

& print_header;
& initialize_dbi;

my $form_ref = &parse_input;
my %FORM_DATA = %$form_ref; 
my $num = $FORM_DATA{'empNum'};
my $name = $FORM_DATA{'empName'};
my $job = $FORM_DATA{'empJob'};
my $loc = $FORM_DATA{'empLoc'};
my $task = $FORM_DATA{'taskID'};
my $msg = "";

# convert task id to UC without spaces
$task =~ tr/a-z/A-Z/;
$task =~ s/^\s*//;
$task =~ s/$\s*//;
$task =~ s/\s+//g;

if ($task eq "") {
	$msg = "NO TASK ID ENTERED";
    adm_add_master_task_msg ($num, $name, $job, $loc, $msg);
} else {
    my $verify = adm_new_master_task_verify ($task);
	if ($verify == 0 ) {		
		adm_master_task_detail_screen  ($num, $name, $job, $loc, $task) ;
	} else {
		$msg = "Master Task $task already exists!";
	    adm_add_master_task_msg ($num, $name, $job, $loc, $msg);
	}
}

db_disconnect();

##################### SUBROUTINES FOLLOW  #####################


sub adm_add_master_task_msg
{
my $num = $_[0];
my $name = $_[1];
my $job = $_[2];
my $loc = $_[3];
my $msg = $_[4];

print <<ENDHEADER;
<html>
<head>
<link rel='stylesheet' type='text/css' href='${css_ref}trak.css' />
<script type='text/javascript' src='${js_ref}trak.js'></script>
<title>trak_02_adm_activity.html</title>
</head>
<h2><center>${banner}</center></h2>
<hr/>
<h3>Add New Master Task</h3>
<div id='box1'>
Employee Number:<br/><br/>
Employee Name:<br/><br/>
New Task ID:<br/><br/>
</div>
<form id='box2' autocomplete='off' name='startJob' action='${cgi_ref}trak_03_adm_add_master_task.pl' method='post'>
<input type="hidden" name=empNum value='$num'/>
<input type="hidden" name=empName value='$name'/>
<input type="hidden" name=empJob value='$job'/>
<input type="hidden" name=empLoc value='$loc'/>
<span>$num</span><br/><br/>
<span>$name</span></b><br/><br/>
<input type="text" size=10 name=taskID />&nbsp&nbsp
<br/><br/>
<input type='submit' name='submit' value='Proceed'>
<br/><br/>
<a href="${cgi_ref}trak_00_adm_activity.pl?num=$num&name=$name&job=$job&loc=$loc">Return to Activities</a>
<br/><br/>
<b id="warn">$msg</b>
<br/><br/>
</form>
</body>
</html>
ENDHEADER

}

sub adm_master_task_detail_screen
{
print <<ENDHEADER;
<html>
<head>
<link rel='stylesheet' type='text/css' href='${css_ref}trak.css' />
<script type='text/javascript' src='${js_ref}trak.js'></script>
<title>trak_03 adm_client_task_detail_screen</title>
</head>
<body>
<h2><center>${banner}</center></h2>
<hr/>
<h3>New Master Task: $task</h3>
<div id='box1'>
Description:<br/><br/>
Units:<br/><br/>
Standard Min:<br/><br/>
</div>
<div id='box2'>
<form autocomplete='off' name='startJob' action='${cgi_ref}trak_04_adm_add_master_task.pl' method='post'>
<input type="hidden" name=empNum value='$num'/>
<input type="hidden" name=empName value='$name'/>
<input type="hidden" name=empJob value='$job'/>
<input type="hidden" name=empLoc value='$loc'/>
<input type="hidden" name=taskID value='$task'/>
<input type="text" name=description size="48"><br/><br/>
<input type="text" name=units size="8"><br/><br/>
<input type="text" name=stdMin size="8"><br/><br/>
Show on the following lists:
<br/><br/>
<label><input type=checkbox name=show_whs>&nbsp&nbsp&nbsp WHS</label>
<label><input type=checkbox name=show_csr>&nbsp&nbsp&nbsp CSR</label>
<label><input type=checkbox name=show_adm>&nbsp&nbsp&nbsp ADMIN</label>
<br/><br/>
<label><input type=checkbox name=inbound>&nbsp&nbsp&nbsp Inbound</label>
<label><input type=checkbox name=outbound>&nbsp&nbsp&nbsp Outbound</label>
<br/><br/>
<input type='submit' name='submit' value='Proceed'>
<br/><br/>
<a href="${cgi_ref}trak_00_adm_activity.pl?num=$num&name=$name&job=$job&loc=$loc">Return to Activities</a>
<br/><br/>
<b id="warn">$msg</b>
<br/><br/>
</div>
</form>
</body>
</html>
ENDHEADER

}


